
const int ledPin_1 = 3;
const int ledPin_2 = 4;
const int ledPin_3 = 5;
const int ledPin_4 = 6;
const int ledPin_5 = 7;

void setup()
{   
  //pinMode(ledPin_2, OUTPUT);
  Serial.begin(9600);
}

#define DF_TEMPADC A0
#define DF_LIGHTADC A1

void loop() {
  char way;
  String light[5];
  if(Serial.available() > 0) {
    way = Serial.read();
    for(int i = 0; i < 5; i++){
      if(way == 'l'){
        light[i] = "";
        while(Serial.available() > 0){
          char character = Serial.read();
          if(character == 'l') break;
          light[i] += char(character);
        }
      }
    }
    analogWrite(ledPin_1, light[0].toInt());
    analogWrite(ledPin_2, light[1].toInt());
    analogWrite(ledPin_3, light[2].toInt());
    analogWrite(ledPin_4, light[3].toInt());
    analogWrite(ledPin_5, light[4].toInt());
//    if(way == '0') {
//      char command;
//      if(Serial.available() > 0) {
//        command = Serial.read();
//        int ledState;
//        if(command == '0') {
//          ledState = LOW;
//        }
//        else {
//          ledState = HIGH;
//        }
//        digitalWrite(ledPin_1, ledState);
//      }
//    }
//    else if(way == 'l') {
//      String light = "";
//      while(Serial.available() > 0) {
//        if(Serial.read() == 'l') break;
//        light += char(Serial.read());
//      }
//      if(light != "") {
//        analogWrite(ledPin_1, light.toInt());
//        analogWrite(ledPin_2, light.toInt());
//        analogWrite(ledPin_3, light.toInt());
//        analogWrite(ledPin_4, light.toInt());
//        analogWrite(ledPin_5, light.toInt());
//      }
//    }
  }
  double a0Val = analogRead(DF_TEMPADC);
  double a1Val = analogRead(DF_LIGHTADC);
  double temp = 1/(log(1024/a0Val - 1)/3435 + 1/(25+273.15))-273.15;
  Serial.println(temp);
  Serial.println(a1Val);
  delay(1000);
}

